package com.platform.qujia.controller;

import com.google.common.collect.Maps;
import com.platform.qujia.pojo.SaleActivity;
import com.platform.qujia.pojo.vo.SaleActivityListVO;
import com.platform.qujia.service.ISaleActivityService;
import com.platform.qujia.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @date 2023/12/25
 */
@RestController
@RequestMapping(value = "/saleActivity")
public class SaleActivityController {

    @Autowired
    private ISaleActivityService saleActivityService;

    @GetMapping("calculateAmt")
    public ResultData<Map<String,String>> calculateAmt(@RequestParam("saleActivityId") Long saleActivityId,
                                                       @RequestParam("purchaseNum") Integer purchaseNum){
        SaleActivity saleActivity = saleActivityService.calculateAmt(saleActivityId, purchaseNum);
        HashMap<String, String> map = Maps.newHashMapWithExpectedSize(2);
        map.put("amt",saleActivity.getPrice().toString());
        map.put("receivableAmt",saleActivity.getOriginalPrice() == null ? null : saleActivity.getOriginalPrice().toString());
        return ResultData.success(map);
    }

    @GetMapping("list/{enterpriseId}")
    public ResultData<List<SaleActivityListVO>> queryListWithoutEnded(@PathVariable Long enterpriseId){
        return ResultData.success(saleActivityService.queryListWithoutEnded(enterpriseId));
    }

}
